package com.yenlien.traceyun.plant.dao;

import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.plant.entity.OKQData;
import com.yenlien.traceyun.webase.dao.BaseJpaDao;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import java.util.List;


public interface OKQDataDao extends BaseJpaDao<OKQData> {







    @Query(value = "SELECT * FROM t_okq WHERE equipment_id = ?1 ORDER BY c_time DESC LIMIT ?2", nativeQuery = true)
    List<OKQData> getLast(String equId, Integer limit);


    @Query(value = "SELECT * FROM t_okq WHERE equipment_id = ?1 AND type = '3' ORDER BY c_time DESC LIMIT ?2", nativeQuery = true)
    List<OKQData> getInsectLast(String equId, Integer limit);


    @Query(value = "SELECT picture_analysis pictureAnalysis, c_time cTime FROM t_okq WHERE equipment_id = ?1 AND type = '3' AND c_time >= DATE_SUB(CURDATE(), INTERVAL 15 DAY)", nativeQuery = true)
    List<JSONObject> getInsectLastSeven(String equId);


    @Query(value = "SELECT * FROM t_okq WHERE equipment_id = ?1 AND c_time BETWEEN ?2 AND ?3", nativeQuery = true)
    List<OKQData> getHistoryData(String equId, String startTime, String endTime);


    @Query(value = "SELECT * FROM t_okq WHERE equipment_id = ?1 ORDER BY c_time DESC", nativeQuery = true)
    Page<OKQData> getHistoryData(String devId, Pageable pageable);


    @Query(value = "SELECT * FROM t_okq WHERE equipment_id = ?1 AND c_time BETWEEN ?2 AND ?3 ORDER BY c_time DESC", nativeQuery = true)
    Page<OKQData> getHistoryData(String devId, String startTime, String endTime, Pageable pageable);




}
